import pandas as pd
import numpy as np

data = pd.read_csv("stock_day.csv")
'''
             open   high  close    low  ...     v_ma5    v_ma10    v_ma20  turnover
2018-02-27  23.53  25.88  24.16  23.53  ...  53782.64  46738.65  55576.11      2.39
2018-02-26  22.80  23.78  23.53  22.80  ...  40827.52  42736.34  56007.50      1.53
2018-02-23  22.88  23.37  22.82  22.71  ...  35119.58  41871.97  56372.85      1.32
2018-02-22  22.25  22.76  22.28  22.02  ...  35397.58  39904.78  60149.60      0.90
2018-02-14  21.49  21.99  21.92  21.48  ...  33590.21  42935.74  61716.11      0.58
'''

# 删除指定列，在pandas中 axis = 1代表列
data = data.drop(["ma5", "ma10", "ma20", "v_ma5", "v_ma10", "v_ma20"], axis=1)
"""
             open   high  close  ...  price_change  p_change  turnover
2018-02-27  23.53  25.88  24.16  ...          0.63      2.68      2.39
2018-02-26  22.80  23.78  23.53  ...          0.69      3.02      1.53
2018-02-23  22.88  23.37  22.82  ...          0.54      2.42      1.32
2018-02-22  22.25  22.76  22.28  ...          0.36      1.64      0.90
2018-02-14  21.49  21.99  21.92  ...          0.44      2.05      0.58
"""

# 在pandas中按照先列后行的方式获取元素
print(data["open"]["2018-02-27"])  # 23.53
# 先行后列
data.loc["2018-02-27":"2018-02-14", ["open", "close"]]
data.iloc[:5, :3]
data.loc[data.index[0:5], ["open", "close"]]
data.iloc[0:5, data.columns.get_indexer(["open", "close"])]

# 赋值与排序
data["open"] = 0
data.open = 0

# 按列排序
data.sort_values(by=["open", "high"], ascending=True)
data["high"].sort_values()

# 按索引排序
data.sort_index(ascending=False)
data["high"].sort_index()